﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace ItemComponent
{
    public interface IAreaTriggerHandler
    {
        void OnEnter2D(Collider2D target);
        void OnExit2D(Collider2D target);
    }

    public class Area : MonoBehaviour
    {
        protected IAreaTriggerHandler triggerHandler;

        public Color color
        {
            get => GetComponentInChildren<SpriteRenderer>().color;
            set => GetComponentInChildren<SpriteRenderer>().color = new Color(value.r,value.g,value.b,0.3f);
        }

        public void InitArea(Battle.ST_RangeData rangeData,IAreaTriggerHandler areaTriggerHandler)
        {
            triggerHandler = areaTriggerHandler;

            transform.localScale = Vector3.one * (float)rangeData.dRadius * 2;

            //TODO 得整个 IDLE 动画
        }

        private void OnTriggerEnter2D(Collider2D collision)
        {
            triggerHandler?.OnEnter2D(collision);
        }
        private void OnTriggerExit2D(Collider2D collision)
        {
            triggerHandler?.OnExit2D(collision);
        }
    }
}
